package game.players.user;

import com.uqbar.vainilla.appearances.Sprite;

import game.ball.Possessed;
import game.ball.SoccerBall;
import game.players.SoccerPlayer;
import game.players.states.WithoutBallSweepingPlayer;
import game.players.user.movements.WithBallStationaryUser;
import game.players.user.movements.WithoutBallStationaryUser;

public class WithoutBallSweepingUserPlayer extends WithoutBallSweepingPlayer {

	public WithoutBallSweepingUserPlayer(SoccerPlayer player, boolean isRight) {
		super(player, isRight);
	}
	
	@Override
	protected void setRightSprite() {
		this.getPlayer().setAppearance(Sprite.fromImage("/images/goal3_barrida2.png").scale(1.5));
	}
	
	@Override
	protected void setLeftSprite() {
		this.getPlayer().setAppearance(Sprite.fromImage("/images/goal3_barrida2.png").scale(1.5).flipHorizontally());
	}
	
	protected void takeTheBall(SoccerBall ball) {
		double advanceX = this.getPlayer().getX() - ball.getX() + ball.getRatio();
		double advanceY = this.getPlayer().getY() + this.getPlayer().getAppearance().getHeight() - ball.getY() - ball.getRatio();
		
		ball.moveNormally(advanceX, advanceY);
	}
	
	public void snatchTheBall() {
		this.getPlayer().setState(new WithBallSweepingUserPlayer(this.getPlayer(), this.isRight()));
		this.getPlayer().getScene().changeBallPossessionTo(this.getPlayer());
	}

	public void takePossession(SoccerBall ball) {
		this.takeTheBall(ball);
		this.getPlayer().setState(new WithBallSweepingUserPlayer(this.getPlayer(), this.isRight()));
		ball.setState(new Possessed(this.getPlayer()));
	}

	public void finishSweep() {
		this.getUpPlayer();
		if (this.getPlayer().isWithBall())
			this.getPlayer().setState(new WithBallStationaryUser(this.getPlayer()));
		else
			this.getPlayer().setState(new WithoutBallStationaryUser(this.getPlayer()));
	}
	
}
